package com.librait.mapstracker;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class RegisterActivity extends ActionBarActivity {

	EditText mUsername;
	EditText mPassword;

	protected String fromEmail;
	protected String emailPassword;
	
	Button signinButton;
	
	protected static SharedPreferences savedData;

	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_signin);
		
		mUsername = (EditText) findViewById(R.id.username);
		mPassword = (EditText) findViewById(R.id.password);
		
		signinButton = (Button) findViewById(R.id.signinButton);
		
		savedData = getSharedPreferences("email", MODE_MULTI_PROCESS);
		savedData = getSharedPreferences("password", MODE_MULTI_PROCESS);
		
		setButtonOnClickListeners();
	}
	
	private void setButtonOnClickListeners(){
		signinButton.setOnClickListener(new OnClickListener(){

			@SuppressLint("CommitPrefEdits")
			@Override
			public void onClick(View arg0) {
				fromEmail = mUsername.getText().toString();
	            emailPassword = mPassword.getText().toString();
	            
	            SharedPreferences.Editor preferencesEditor = savedData.edit();
	            
	            preferencesEditor.putString("email", fromEmail);
	            preferencesEditor.putString("password", emailPassword);
	            preferencesEditor.apply();
	            
	            Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
	            startActivity(intent);
	            finish();
			}
			
		});
		
	}
	public static String getSavedString(String str){
		return savedData.getString(str, "Couldn't find string");
	}
}
